Skip to content

feat(core): filter sessions by path and add setting to disable#24849

Merged
jlongster merged 2 commits into
devfrom
jlongster/session-filter
Apr 28, 2026
Merged

feat(core): filter sessions by path and add setting to disable#24849
jlongster merged 2 commits into
devfrom
jlongster/session-filter

Conversation

@jlongster

@jlongster jlongster commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Previously, we tracked the absolute path for each session. The session list endpoint happens to accept directory to filter on, and this conflicted with the global SDK directory param. We just happened to be filtering by directory because the SDK sends that parameter for all requests.

This is a feature we want to support though: for people in big monorepos it's useful to filter sessions by the directory you opened in. However, we can't use the absolute path: the sessions might be in a git worktree or remote workspace with a different absolute path, but the relative path should be the same. So we started tracking the relative path in the path field, and this PR changes the filtering to filter based on that

You can now optionally disable this so you always get all sessions for the project regardless of where you opened OpenCode

Previous sessions will not have path set; in this case we will still fallback to the same filtering as before

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds directory-aware filtering for TUI session lists while preserving existing session list API behavior. The session list endpoint now supports explicit project-wide listing and project-relative path filtering, including a fallback for older sessions with path = NULL.
The TUI now scopes sessions to the current directory by default, with a command menu toggle to disable directory scoping and list all sessions for the project.

How did you verify your code works?

  • bun test test/server/session-list.test.ts
  • bun test test/cli/cmd/tui/sync.test.tsx
  • bun typecheck
  • Pre-push hook: bun turbo typecheck

Screenshots / recordings

Not included.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@jlongster jlongster merged commit 9209c04 into dev Apr 28, 2026
17 checks passed
@jlongster jlongster deleted the jlongster/session-filter branch April 28, 2026 20:49
afanty2021 added a commit to afanty2021/opencode that referenced this pull request Apr 29, 2026
Upstream commits:
- fix: clear timeout after promise rejection (anomalyco#24864)
- chore: generate
- fix(bash): memory leak - release parsed syntax trees (anomalyco#24861)
- feat(core): filter sessions by path and add setting to disable (anomalyco#24849)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

# Conflicts:
#	packages/core/CLAUDE.md
#	packages/core/src/util/CLAUDE.md
oleksii-honchar pushed a commit to oleksii-honchar/better-opencode that referenced this pull request Apr 29, 2026
@malventano

malventano commented May 7, 2026

Copy link
Copy Markdown

This breaks the previous behavior and causes opencode -c in a parent to open the most recently closed child session (which may have been in a subdir) in the parent's pwd. This can lead the user to inadvertently effectively bypass their external_directory security setting as the session meant to be in the child path is now open in the parent, and now has access to all other children of that parent.

Your disable option kills the filtering entirely, which is even worse for users tripping over the above, and it leaves no way to restore the previous behavior. The prior behavior should have started as the default moving forward from this PR else all users will run into the above issue.

@chenxuan520

Copy link
Copy Markdown

Now sessions from subdirectories are appearing in the parent directory, which is very bad and incompatible. I think it's a bug.

@malventano

malventano commented Jun 7, 2026

Copy link
Copy Markdown

Now sessions from subdirectories are appearing in the parent directory, which is very bad and incompatible. I think it's a bug.

I submitted #31210 which should restore the behavior for cases outside of what this PR intended to address (it did so too broadly and roped in non-git cases).

@jlongster please review #31210 as it refines the scope of your earlier PR - it's led to a string of issues and even cases where users may continue a session context from within its parent folder, which can lead to edits outside of the intended external_directory of that session).

isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 9, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
thisxiangyu added a commit to thisxiangyu/opencode-fork that referenced this pull request Jun 15, 2026
将 upstream/dev (38adc13) 合并到 dev-custom,解决 14 个文件的合并冲突,
同时修复因上游模块迁移导致的构建错误。构建与 Smoke Test 全部通过。

## 上游主要更新

- **HttpApi 后端重构与完整测试覆盖**:authorization middleware、instance context、
  workspace routing、websocket proxy、SDK parity、Effect HttpApi backend parity。
- **桌面端修复**:路径匹配导致 sessions 丢失、强 ID、现有数据修复 (anomalyco#25013)。
- **模型支持**:新增 Mistral Medium 3.5 with reasoning (anomalyco#24996)。
- **参数调整**:Azure/DeepSeek 默认参数优化;系统提示词顺序调整为 Global → Project → Skills。
- **Session 路径**:新增按路径过滤 session 及禁用设置 (anomalyco#24849);数据库新增 session_path、
  icon_url_override 字段。
- **TUI 体验**:粘贴摘要开关更易用 (anomalyco#24869)。
- **内存泄漏修复**:Bash 工具释放解析后的语法树 (anomalyco#24861)。
- **MCP 健壮性**:无效 MCP URL 处理修复 (anomalyco#25019)。
- **核心模块迁移**:global、filesystem、flag、log、npm、effect 等大量底层模块从
  packages/opencode 迁移到 packages/core,建立更清晰的分层。
- **版本同步**:v1.14.30。

## 本地定制功能保全

以下本地特有功能在合并中完全保全,未受上游更新影响:

- **StrategyLoops 轻量框架**:StrategyLoops/ 目录下 PEE/MPEE 模块、Role/Session 管理、
  opencode 适配器等全部保留。
- **可配置存储路径**:database、log、worktree、snapshot 路径支持环境变量与配置文件自定义。
- **日志系统增强**:log-tee 模式(同时输出到文件与控制台)、可配置日志目录。
- **Snapshot 优化**:使用本地 ignore 库替代 git check-ignore,避免 Windows ENAMETOOLONG;
  文件夹级忽略的批量删除逻辑完整保留。
- **MCP 面板项目名提示**:status-popover-body.tsx 中当前项目名展示保留。
- **设置页路径展示**:settings-general.tsx 中 worktree/snapshot/config 路径加载与展示保留。
- **分叉版本构建工作流**、中文贡献文档、定制 i18n 键等全部保留。

## 冲突解决与代码整合

| 文件 | 冲突处理策略 |
|------|-------------|
| dialog-edit-project.tsx | 采用上游提取的 getProjectAvatarSource() 函数,同时保留本地 override/url/color 完整逻辑 |
| sidebar-items.tsx / layout.tsx | 整合上游头像来源逻辑,保留本地 icon override 与 color 判定 |
| settings-general.tsx | 保留本地 loadConfigFiles / loadWorktreeInfo / loadSnapshotInfo 及路径展示 UI;合并上游新增的 shell / displayBackend 等逻辑 |
| status-popover-body.tsx | 保留本地 projectName 提示;去除上游删除的废弃 load 状态 |
| config/config.ts | 采纳上游 Schema 修正(ConfigAgent.Info 替换 AgentRef;MCP 禁用配置改用 Schema.Struct) |
| server/event.ts | 保留本地 ConfigUpdated 事件定义,同时合并上游 Schema 化改造 |
| server/routes/global.ts | 完整保留本地特有的 /storage/* 与 /config/path 路由;合并上游模块导入路径重构 |
| snapshot/index.ts | 修正导入路径到 @opencode-ai/core/*,保留本地 ignore 库、StorageConfig、Flag 等全部定制 |
| worktree/index.ts | 同上,修正模块路径,保留本地 StorageConfig / Flag / resolveDir 等定制 |

## 构建修复(模块迁移适配)

上游将 global、flag 等模块迁移到 packages/core 后,本地定制代码出现模块解析失败:

1. **StorageConfig 跨包迁移**:将 storage-config.ts 从 opencode 包迁移到
   packages/core/src/storage/storage-config.ts,原位置改为重新导出;解除 core → opencode
   的反向依赖,避免循环依赖。
2. **依赖补充**:core/package.json 新增 jsonc-parser 依赖(原仅在 opencode 中声明)。
3. **导入路径修正**:core/src/util/log.ts、snapshot/index.ts、worktree/index.ts 中的
   ../global、../flag/flag、../storage/storage-config 等相对路径统一修正为
   @opencode-ai/core/* 路径。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants